package io.github.fb513.api;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.TemplateType;
import com.baomidou.mybatisplus.generator.config.rules.DateType;

import java.util.Collections;

/**
 * Mybatis-Plus代码生成器
 * <a href="https://juejin.cn/post/7153855035896512526">使用指南</a>
 * @author fengbo
 */
public class CodeGenerator {

    private static final String parentPackage = "io.github.fb513.api";
    private static final String moduleName = "im-web-api";
    private static final String url = "jdbc:mysql://121.41.39.119:3306/mini_im?useUnicode=true&characterEncoding=utf-8&useSSL=false";
    private static final String username = "mini_im";
    private static final String password = "42134213";
    private static final String tablePrefix = "im_";

    public static void main(String[] args) {

        String projectPath = System.getProperty("user.dir");
        FastAutoGenerator.create(url, username, password)
                .globalConfig(builder -> {
                    builder.author("fengbo")
                            .outputDir(projectPath + "/" + moduleName + "/src/main/java")
                            .disableOpenDir()
                            .dateType(DateType.TIME_PACK);
                })
                .packageConfig(builder -> {
                    builder.parent(parentPackage)
                            .entity("entity")
                            .mapper("mapper")
                            .pathInfo(Collections.singletonMap(OutputFile.xml, projectPath + "/" + moduleName + "/src/main/resources/mapper"))
                            .service("service")
                            .serviceImpl("service.impl")
                            ;
                })
                .strategyConfig((scanner, builder) -> {
                    builder.addInclude(scanner.apply("请输入表名，多个英文逗号分隔？所有输入"))
                            .addTablePrefix(tablePrefix)
                            .entityBuilder()
                            .fileOverride()
                            .enableLombok()
                            .disableSerialVersionUID()
                            .controllerBuilder()
                            .enableRestStyle();
                })
                .templateConfig(builder -> {
                    builder.disable(TemplateType.CONTROLLER);
                })
                .execute();


    }

}
